#!/bin/sh

SYSLOG_CONF=/etc/syslog.conf
SUDO_LOG=/var/log/sudo.log
NEWSYSLOG_CONF=/etc/newsyslog.conf

if [ $2 != "POST-INSTALL" ]; then
  exit 0
fi

if [ -e ${PKG_PREFIX}/etc/sudoers ]; then
  echo "Will not overwrite existing ${PKG_PREFIX}/etc/sudoers file."
else
  cp -p ${PKG_PREFIX}/etc/sudoers.default ${PKG_PREFIX}/etc/sudoers
  chmod 440 ${PKG_PREFIX}/etc/sudoers
fi

if [ ! -e ${SYSLOG_CONF} ]; then
  touch ${SYSLOG_CONF}
fi

if [ -e ${SYSLOG_CONF} ]; then
echo -n "Spamming ${SYSLOG_CONF}..."
cat >> ${SYSLOG_CONF} << EOF
# Begin CS sudo log
# Do not touch these lines
!sudo
*.*			/var/log/sudo.log
# End CS sudo log
EOF
echo "Done."
fi

if [ ! -e ${SUDO_LOG} ]; then
	touch ${SUDO_LOG}
	chmod 440 ${SUDO_LOG}
fi

if [ ! -e ${NEWSYSLOG_CONF} ]; then
	touch ${NEWSYSLOG_CONF}
fi

if [ -e ${NEWSYSLOG_CONF} ]; then
echo -n "Spamming ${NEWSYSLOG_CONF}..."
cat >> ${NEWSYSLOG_CONF} << EOF
# Begin CS sudo log
# Do not touch these lines
/var/log/sudo.log	root:security	640  7     *	\$M1D0  Z
# End CS sudo log
EOF
echo "Done."
fi
